package com.atguigu.rabbitmq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 杨林
 * @create 2022-10-06 13:38 星期四
 * description:获取rabbitmq连接的工具类
 */
public class ConnectionUtil {

    public static com.rabbitmq.client.Connection getConnection() throws IOException, TimeoutException {
        //创建工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置主机地址
        factory.setHost("192.168.10.128");
        //连接端口  默认端口5672
        factory.setPort(5672);
        //设置虚拟主机名称
        factory.setVirtualHost("/");
        //设置连接用户名
        factory.setUsername("admin");
        //连接密码
        factory.setPassword("admin");
        //创建连接
        com.rabbitmq.client.Connection connection = factory.newConnection();
        return connection;
    }
}
